package com.hqyj.javaSpringBoot.modules.test.dao;

import com.hqyj.javaSpringBoot.modules.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CountryDao {

    /**根据国家id查询国家*/
    @Select("select * from test_country where country_id=#{countryId}")
    @Results(id = "countryResults",value = {
            @Result(column = "country_id",property = "countryId"),
            @Result(column = "country_id",property = "cities",javaType = List.class,
            many = @Many(select ="com.hqyj.javaSpringBoot.modules.test.dao.CityDao.getCitiesByCountryId"))
    })
    Country getCountryByCountryId(int countryId);

    /**
     * 根据国家名称查询国家
     * @ResultMap(value = "countryResults")引用上面一个的@Results
     */
    @Select("select * from test_country where country_name=#{countryName}")
    @ResultMap(value = "countryResults")
    Country getCountryByCountryName(String countryName);
}
